package com.example.friendmanager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ContactHolder> {

    private List<ContactModel>data;

    public void setData(List<ContactModel> data) {
        this.data = data;
    }

    private Context context;

    public CustomAdapter(Context context) {
        this.context = context;
    }

    @Override
    public ContactHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ContactHolder(LayoutInflater.from(context).inflate(R.layout.list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull ContactHolder holder, int position) {
        holder.icon.setImageResource(data.get(position).getFtouxiang());
        holder.filename.setText(data.get(position).getFname());
    }

    @Override
    public int getItemCount() {
        return null!=data?data.size():0;
    }

    class ContactHolder extends RecyclerView.ViewHolder{

        private ImageView icon;
        private TextView filename;

        public ContactHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.icon);
            filename=itemView.findViewById(R.id.filename);
        }
    }
}
